package com.dyh.quickdemozwei.mja;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {


    public static void main(String[] args) throws Exception {
        ClassPool cp = ClassPool.getDefault();

        CtClass ctClass = cp.getCtClass("ch.qos.logback.classic.Logger");

        for (CtMethod method : ctClass.getMethods()) {
            if (method.getName().startsWith("error")){

                method.insertBefore("System.out.println(\"before!!\");");
            }
        }


        Class classAft = ctClass.toClass();

        Logger logger = LoggerFactory.getLogger(Main.class);

        logger.error("dawdaw");
//        Ytq ytq = (Ytq) classYtq.newInstance();
//        ytq.sleep();
    }

}
